<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use App\Card;
class CardController extends Controller
{
    //创建卡卷
    public function create(){
    	$receivers = User::pluck('name','id');
    	$user_id = \Auth::id();
    	unset($receivers[$user_id]);
    	$time = date("Y-m-d",strtotime("+3 month"));
    	return view('card/create',compact('receivers','time'));
    }
    //存储卡卷
    public function store(Card $card){
    	//验证
    	$this->validate(request(),[
    		'name' => 'required|string|max:100|min:3',
    		'des' => 'required|string|min:5',
    		'receive_id' => 'required|integer|min:1',
    		'headline_time' => 'required|min:5'
    	]);
    	//逻辑
    	$params = request(['name','des','receive_id','headline_time']);
    	$params['origin_id'] = \Auth::id();
    	Card::Create($params);
    	// dd(\Request::all());
    	// dd(request());
    	//渲染
    	return redirect("./card");
    	//渲染
    }
    //卡卷列表页
    public function index(){
    	$cards = Card::orderBy('created_at','desc')->paginate(6);
    	// dd($cards);
    	return view('card/index',compact('cards'));
    }
}
